package com.anuprayog.treasureloot.model;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;

/**
 * Bag
 * 
 * @author amit
 */
public class Bag {

   private Bitmap bitmap;  // the actual bitmap
   private int x;          // the X coordinate
   private int y;          // the Y coordinate
   private boolean touched;    // if droid is touched/picked up
    
   public Bag(Bitmap bitmap, int x, int y) {
       this.bitmap = bitmap;
       this.x = x;
       this.y = y;
   }
    
   public Bitmap getBitmap() {
       return bitmap;
   }
   public void setBitmap(Bitmap bitmap) {
       this.bitmap = bitmap;
   }
   public int getX() {
       return x;
   }
   public void setX(int x) {
       this.x = x;
   }
   public int getY() {
       return y;
   }
   public void setY(int y) {
       this.y = y;
   }

   public boolean isTouched() {
       return touched;
   }

   public void setTouched(boolean touched) {
       this.touched = touched;
   }
    
   public void draw(Canvas canvas) {
       //canvas.drawBitmap(bitmap, x - (bitmap.getWidth() / 2), y - (bitmap.getHeight() / 2), null);
       canvas.drawBitmap(bitmap, null, new Rect(x - (bitmap.getWidth() / 2), y - (bitmap.getHeight() / 2),x - (bitmap.getWidth() / 2) + canvas.getWidth()/12, y - (bitmap.getHeight() / 2) + canvas.getHeight()/15), null);
   }

   public void handleActionDown(int eventX, int eventY) {
       if (eventX >= (x - bitmap.getWidth()) && (eventX <= (x + bitmap.getWidth()))) {
           if (eventY >= (y - bitmap.getHeight()) && (eventY <= (y + bitmap.getHeight()))) {
               // droid touched
               setTouched(true);
           } else {
               setTouched(false);
           }
       } else {
           setTouched(false);
       }

   }
}
